package com.tamplus.cs.service;

import java.util.ArrayList;
import java.util.Date;

import javax.xml.rpc.holders.StringHolder;

import org.apache.commons.beanutils.BeanUtils;
import org.tempuri.CheckUpServiceSoapProxy;
import org.tempuri.O_Product_Recommend_Get_result;
import org.tempuri.O_Product_Recommend_Search_History;
import org.tempuri.O_Rick_Factor;
import org.tempuri.Or_Answer_Info;
import org.tempuri.Or_Patient_Info;
import org.tempuri.Otr_Checkup_record;

import com.siebel.CustomUI.AddContact_Input;
import com.siebel.CustomUI.AddContact_Output;
import com.siebel.CustomUI.BGH_spc_spcAdd_spcContactProxy;
import com.siebel.CustomUI.BGH_spc_spcGet_spcContact_spcInfoProxy;
import com.siebel.CustomUI.BGH_spc_spcProduct_spcRecommendationProxy;
import com.siebel.CustomUI.BGH_spc_spcUpdate_spcAnswerProxy;
import com.siebel.CustomUI.BGH_spc_spcUpdate_spcProductProxy;
import com.siebel.CustomUI.GetContactInfo_Input;
import com.siebel.CustomUI.GetContactInfo_Output;
import com.siebel.CustomUI.UpdateAnswer_Input;
import com.siebel.CustomUI.UpdateAnswer_Output;
import com.siebel.CustomUI.UpdateProduct_Input;
import com.siebel.CustomUI.UpdateProduct_Output;
import com.tamplus.cs.constant.Constant;
import com.tamplus.cs.constant.MessageConstant;
import com.tamplus.cs.exception.CSException;
import com.tamplus.cs.model.CheckupPackage;
import com.tamplus.cs.model.Patient;
import com.tamplus.cs.util.BusinessUtils;
import com.tamplus.cs.util.DateUtils;
import com.tamplus.cs.util.StringUtils;


public class CallService extends BaseService{
	private void manageResult(String _isComplete, String _errorMessage) throws CSException{
		//manage output
		System.out.println("Is Complete : "+_isComplete);
		System.out.println("errorMsg : "+_errorMessage);
		
		//manage error
		if(Constant.STATUS_FAIL.equalsIgnoreCase(_isComplete)){
			throw new CSException(_errorMessage);
		}
	}
	
	public Patient getPatientProfile(String hn) throws CSException, Exception{
		System.out.println("Start getPatientProfile...");
		Patient patient = new Patient();
		
		System.out.println("HN is "+hn);
		CheckUpServiceSoapProxy service = getService(MessageConstant.END_POINT_SEARCH_HISTORY);
		System.out.println("start get resultd..");
		O_Product_Recommend_Search_History result = service.XX_Product_Recommend_Search_History(hn);
		//get patient info
		Or_Patient_Info info = result.getOr_Patient_Info();
		System.out.println("patient result.."+info);
		convertPatientToModel(info, patient);
		
		patient.setHnFlag(result.getO_HN_Flag());
		patient.setCheckupFlag(result.getO_Checkup_Flag());
		
		//get check-up record
		Otr_Checkup_record[] detail = result.getOtr_checkup_record();
		System.out.println("detail result.."+detail);
		convertCheckupRecordToList(detail, patient);
		
		//manage output
		manageResult(result.getIsComplete(), result.getErrorMessage());
			
		System.out.println("End getPatientProfile...");
		return patient;
	}
	
	private void convertPatientToModel(Or_Patient_Info info, Patient patient) throws Exception{
		if(info == null) return;
		System.out.println(BeanUtils.describe(info));						
		
		patient.setHn(StringUtils.toString(info.getC_HN_No()));
		patient.setName(StringUtils.toString(info.getC_Name()));
		patient.setGender(StringUtils.toString(info.getC_Gender()));
		patient.setDOB(DateUtils.getDateStr(DateUtils.createDate(info.getC_DOB(), "MM/dd/yyyy"), "dd/MM/yyyy"));
//		patient.setBirthDate(DateUtils.createDate(info.getC_DOB(), "dd/MM/yyyy hh:mm:ss a"));
		patient.setBirthDate(DateUtils.createDate(info.getC_DOB(), "MM/dd/yyyy"));
		patient.setAge(StringUtils.toString(info.getC_Age()));
		patient.setContactId(StringUtils.toString(info.getC_ContactID()));
	}
	
	private void convertCheckupRecordToList(Otr_Checkup_record[] detail, Patient patient) throws Exception{
		convertCheckupRecordToList(detail, patient, false);
	}
	private void convertCheckupRecordToList(Otr_Checkup_record[] detail, Patient patient, boolean isNew) throws Exception{
		ArrayList<CheckupPackage> result = new ArrayList<CheckupPackage>();
		
		if(detail == null || detail.length == 0) return;
		
		double totalPrice = 0;
		CheckupPackage package1 = null;
		for(Otr_Checkup_record record : detail){
			package1 = new CheckupPackage();
			
			System.out.println(BeanUtils.describe(record));
			String rowId = "".equals(StringUtils.toString(record.getC_Row_id()))?StringUtils.toString(record.getC_Prod_Row_id()):StringUtils.toString(record.getC_Row_id());
			package1.setId(rowId);
			package1.setVisitDate(DateUtils.createDate(record.getC_Visit_Date(), "MM/dd/yyyy"));
			package1.setVisitDateStr(DateUtils.getDateStr(DateUtils.createDate(record.getC_Visit_Date(), "MM/dd/yyyy"), "dd/MM/yyyy"));
			String packageName = "".equals(StringUtils.toString(record.getC_Checkup_Package()))?StringUtils.toString(record.getC_Package_Name()):StringUtils.toString(record.getC_Checkup_Package());
			package1.setPackageName(packageName);
			package1.setStatus(StringUtils.toString(record.getC_Status()));
			package1.setDescription(StringUtils.toString(record.getC_Description()));
			String select 	= StringUtils.toString(record.getC_Select());
			if(isNew){
				select		= Constant.FLAG_S.equalsIgnoreCase(StringUtils.toString(record.getC_Other_Flag()))?Constant.FLAG_Y:Constant.FLAG_N;
				
			}
			String price 	= "".equals(StringUtils.toString(record.getC_Amount()))?StringUtils.toString(record.getC_Price()):StringUtils.toString(record.getC_Amount());
			if(Constant.FLAG_Y.equalsIgnoreCase(select)){
				totalPrice += StringUtils.parseDouble(price);
			}
			package1.setPrice(StringUtils.parseDouble(price));
			package1.setAmount(StringUtils.parseDouble(price));
			package1.setIndication(StringUtils.toString(record.getC_Indication()));
			package1.setRemark(record.getC_Remark());
			package1.setSelect(select);
			package1.setOtherFlag(record.getC_Other_Flag());
			result.add(package1);
		}
		
		patient.setPackageList(result);
		patient.setTotalPrice(totalPrice);
	}
	
	private void convertAnswerToModel(Or_Answer_Info info, Patient patient) throws Exception{
		if(info == null) return;
		System.out.println(BeanUtils.describe(info));						
		
		patient.setBMI(info.getC_BMI());
		patient.setDIA(info.getC_DIA());
		patient.setHeart(info.getC_Heart());
		patient.setHeight(info.getC_Height());
		patient.setNote(info.getC_Note());
		patient.setStatus(info.getC_Status());
		patient.setSYS(info.getC_SYS());
		patient.setTotalPrice(StringUtils.parseDouble(info.getC_Total_Price()));
		patient.setVisitDate(DateUtils.createDate(info.getC_Visit_Date(), "MM/dd/yyyy"));
		patient.setVisitDateStr(DateUtils.getDateStr(DateUtils.createDate(info.getC_Visit_Date(), "MM/dd/yyyy"), "dd/MM/yyyy"));
		patient.setWeight(info.getC_Weight());
		patient.setAnswerId(info.getC_AnswerID());
	}
	
	public Patient getPackageResult(String rowNo, boolean isNew) throws CSException, Exception{
		System.out.println("Start getPackageResult...");
		Patient patient = new Patient();
	
		System.out.println("ID is "+rowNo);
		CheckUpServiceSoapProxy service = getService(MessageConstant.END_POINT_GET_RESULT);
		System.out.println("start get resultd..");
		O_Product_Recommend_Get_result result = service.XX_Product_Recommend_Get_result(rowNo);
		
		//get patient info
		Or_Patient_Info info = result.getOr_Patient_Info();
		System.out.println("patient result.."+info);
		convertPatientToModel(info, patient);
		
		//get answer result
		Or_Answer_Info answerInfo = result.getOr_Answer_Info();
		System.out.println("answer info.."+answerInfo);
		convertAnswerToModel(answerInfo, patient);

		//get check-up record
		Otr_Checkup_record[] detail = result.getOtr_Checkup_Record();
		System.out.println("detail result.."+detail);
		convertCheckupRecordToList(detail, patient, isNew);
		
		O_Rick_Factor riskFactory = result.getO_Rick_Factor();
		if(riskFactory != null){
			patient.setRiskFactory(riskFactory.getC_Rick_Factor());
		}
		
		//manage output
		manageResult(result.getIsComplete(), result.getErrorMessage());
			
		System.out.println("visit date : "+patient.getVisitDate());
		System.out.println("visit date[format] : "+DateUtils.getDateStr(patient.getVisitDate(), "dd/MM/yyyy"));
		System.out.println("End getPackageResult...");		
		
		return patient;
	}
	
	public Patient getPackageResult(String rowNo) throws CSException, Exception{		
		return getPackageResult(rowNo, false);
	}	
	
	public void addContract(Patient patient) throws CSException, Exception{
		System.out.println("Start addContract...");
		
		BGH_spc_spcAdd_spcContactProxy service = getAddContractService(MessageConstant.END_POINT_ADD_CONTRACT);
//service.setEndpoint("http://172.18.32.129/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&UserName=" + user + "&Password=" + passwd);
		
		System.out.println("start get resultd..");
		
		AddContact_Input input = new AddContact_Input();
		
		input.setHN(patient.getHn());
		input.setTitle(patient.getTitle());
		input.setName(patient.getName());
		input.setLastName(patient.getSurname());
		input.setGender(patient.getGender());
//		input.setBirthdate(DateUtils.getDateStr(patient.getBirthDate(), "dd/MM/yyyy"));
		input.setBirthdate(DateUtils.getDateStr(patient.getBirthDate(), "MM/dd/yyyy"));
		
		AddContact_Output output = service.addContact(input);
		System.out.println("output : "+output);
		if(output != null){
			System.out.println("contractId : "+output.getContactId());
			System.out.println("isComplete : "+output.getIsComplete());
		
			patient.setContactId(output.getContactId());

			//manage output
			manageResult(output.getIsComplete(), output.getErrorMessage());
		}
			
		System.out.println("End addContract...");
	}	
	
	public Patient getContract(String hn) throws CSException, Exception{
		System.out.println("Start getContract...");
		System.out.println("HN is :"+hn);
		Patient patient = new Patient();
		patient.setHn(hn);
	
		BGH_spc_spcGet_spcContact_spcInfoProxy service = getGetContractService(MessageConstant.END_POINT_GET_CONTRACT);
		System.out.println("start get resultd..");
		
		GetContactInfo_Input input = new GetContactInfo_Input();
		input.setHN(hn);
		
		GetContactInfo_Output output = service.getContactInfo(input);
		System.out.println(output);
		if(output != null){
			System.out.println("output : "+BeanUtils.describe(output));
			patient.setTitle(output.getTitle());
			patient.setName(output.getFirstName());
			patient.setSurname(output.getLastName());
			patient.setGender(output.getGender());
			patient.setBirthDate(DateUtils.createDate(output.getBirthDate(), "MM/dd/yyyy"));
			patient.setDOB(DateUtils.getDateStr(DateUtils.createDate(output.getBirthDate(), "MM/dd/yyyy"), "dd/MM/yyyy"));
			patient.setAge(output.getAge());
			
			//manage output
			manageResult(output.getIsComplete(), output.getErrorMessage());
		}

		System.out.println("End getContract...");
		return patient;
	}	
	
	public void recommend(Patient patient, 
							String option01,
							String option02,
							String option03,
							String option04,
							String option05,
							String option06,
							String option07,
							String option08,
							String option09,
							String option10,
							String option11,
							String option12,
							String option13,
							String option14,
							String option15,
							String option16,
							String option17,
							String option18,
							String option19,
							String option20,
							String option21,
							String option22,
							String option23,
							String option24,
							String option25,
							String option26,
							String option27,
							String option28,
							String option29,
							String option30,
							String option31,
							String option04_1,
							String option15_1,
							String option16_1,
							String option17_1
						) throws CSException, Exception{
		System.out.println("Start recommend...");		
	
		option01 			= BusinessUtils.getFlag(option01);
		option02 			= BusinessUtils.getFlag(option02);
		option03 			= BusinessUtils.getFlag(option03);
		option04 			= BusinessUtils.getFlag(option04);
		option05 			= BusinessUtils.getFlag(option05);
		option06 			= BusinessUtils.getFlag(option06);
		option07 			= BusinessUtils.getFlag(option07);
		option08 			= BusinessUtils.getFlag(option08);
		option09 			= BusinessUtils.getFlag(option09);
		option10 			= BusinessUtils.getFlag(option10);
		option11 			= BusinessUtils.getFlag(option11);
		option12 			= BusinessUtils.getFlag(option12);
		option13 			= BusinessUtils.getFlag(option13);
		option14 			= BusinessUtils.getFlag(option14);
		option15 			= BusinessUtils.getFlag(option15);
		option16 			= BusinessUtils.getFlag(option16);
		option17 			= BusinessUtils.getFlag(option17);
		option18 			= BusinessUtils.getFlag(option18);
		option19 			= BusinessUtils.getFlag(option19);
		option20 			= BusinessUtils.getFlag(option20);
		option21 			= BusinessUtils.getFlag(option21);
		option22 			= BusinessUtils.getFlag(option22);
		option23 			= BusinessUtils.getFlag(option23);
		option24 			= BusinessUtils.getFlag(option24);
		option25 			= BusinessUtils.getFlag(option25);
		option26 			= BusinessUtils.getFlag(option26);
		option27 			= BusinessUtils.getFlag(option27);
		option28 			= BusinessUtils.getFlag(option28);
		option29 			= BusinessUtils.getFlag(option29);
		option30 			= BusinessUtils.getFlag(option30);
		option31 			= BusinessUtils.getFlag(option31);	
//		option04_1			= StringUtils.isEmpty(option04)?BusinessUtils.FLAG_NULL:option04_1;
//		option15_1 			= StringUtils.isEmpty(option15)?BusinessUtils.FLAG_NULL:option15_1;
//		option16_1 			= StringUtils.isEmpty(option16)?BusinessUtils.FLAG_NULL:option16_1;
//		option17_1 			= StringUtils.isEmpty(option17)?BusinessUtils.FLAG_NULL:option17_1;		
//		String visitDate	= DateUtils.getDateStr(patient.getVisitDate(), "dd/MM/yyyy");
		String visitDate	= DateUtils.getDateStr(patient.getVisitDate(), "MM/dd/yyyy");
		String age			= patient.getAge();
		String ageRange01	= BusinessUtils.checkAge(age, "26", BusinessUtils.OPER_LESS_THAN_EQUALS);
		String ageRange02	= BusinessUtils.checkAge(age, "21", BusinessUtils.OPER_MORE_THAN);
		String ageRange03	= BusinessUtils.checkAge(age, "50", BusinessUtils.OPER_MORE_THAN);
		String ageRange04	= BusinessUtils.checkAge(age, "60", BusinessUtils.OPER_MORE_THAN);
		String ageRange05	= BusinessUtils.checkAge(age, "45", BusinessUtils.OPER_MORE_THAN);
		String ageRange06	= BusinessUtils.checkAge(age, "65", BusinessUtils.OPER_MORE_THAN);
		String ageRange07	= BusinessUtils.checkAgeScope(age, "40", "75");
		String ageRange08	= BusinessUtils.checkAge(age, "40", BusinessUtils.OPER_MORE_THAN);
		String ageRange09	= BusinessUtils.checkAge(age, "30", BusinessUtils.OPER_MORE_THAN);
		String ageRange10	= "";
		String ageRange11	= "";
		String ageRange12	= "";
		String ageRange13	= "";
		String ageRange14	= "";
		String ageRange15	= "";
		int year04			= StringUtils.isEmpty(option04_1)?0:StringUtils.parseInt(age)-StringUtils.parseInt(option04_1);
		String option04_2 	= BusinessUtils.FLAG_Y.equals(option04)&&!StringUtils.isEmpty(option04_1)?BusinessUtils.checkAge(""+year04, "15", BusinessUtils.OPER_MORE_THAN):BusinessUtils.FLAG_NULL;
		String option04_3 	= BusinessUtils.FLAG_NULL;
		String option15_2 	= BusinessUtils.FLAG_Y.equals(option15)?BusinessUtils.checkAge(option15_1, "60", BusinessUtils.OPER_LESS_THAN):BusinessUtils.FLAG_NULL;
		int year15			= StringUtils.isEmpty(option15_1)?0:StringUtils.parseInt(option15_1)-StringUtils.parseInt(age);
		String option15_3 	= BusinessUtils.FLAG_Y.equals(option15)&&!StringUtils.isEmpty(option15_1)?BusinessUtils.checkAge(""+year15, "10", BusinessUtils.OPER_LESS_THAN_EQUALS):BusinessUtils.FLAG_NULL;
		String option16_2 	= BusinessUtils.FLAG_Y.equals(option16)?BusinessUtils.checkAge(option16_1, "60", BusinessUtils.OPER_LESS_THAN):BusinessUtils.FLAG_NULL;
		int year16			= StringUtils.isEmpty(option16_1)?0:StringUtils.parseInt(option16_1)-StringUtils.parseInt(age);
		String option16_3 	= BusinessUtils.FLAG_Y.equals(option16)&&!StringUtils.isEmpty(option16_1)?BusinessUtils.checkAge(""+year16, "10", BusinessUtils.OPER_LESS_THAN_EQUALS):BusinessUtils.FLAG_NULL;
		String option17_2 	= BusinessUtils.FLAG_Y.equals(option17)?BusinessUtils.checkAge(option17_1, "60", BusinessUtils.OPER_LESS_THAN):BusinessUtils.FLAG_NULL;
		int year17			= StringUtils.isEmpty(option17_1)?0:StringUtils.parseInt(option17_1)-StringUtils.parseInt(age);
		String option17_3 	= BusinessUtils.FLAG_Y.equals(option17)&&!StringUtils.isEmpty(option17_1)?BusinessUtils.checkAge(""+year17, "10", BusinessUtils.OPER_LESS_THAN_EQUALS):BusinessUtils.FLAG_NULL;
		
		System.out.println("input.................");
		System.out.println("contactId: "+patient.getContactId());
		System.out.println("height   : "+patient.getHeight());
		System.out.println("weight   : "+patient.getWeight());
		System.out.println("DIA      : "+patient.getDIA());
		System.out.println("heart    : "+patient.getHeart());
		System.out.println("SYS      : "+patient.getSYS());
		System.out.println("gender   : "+patient.getGender());
		System.out.println("option01 : "+option01);
		System.out.println("option02 : "+option02);
		System.out.println("option03 : "+option03);
		System.out.println("option04 : "+option04);
		System.out.println("option05 : "+option05);
		System.out.println("option06 : "+option06);
		System.out.println("option07 : "+option07);
		System.out.println("option08 : "+option08);
		System.out.println("option09 : "+option09);
		System.out.println("option10 : "+option10);
		System.out.println("option11 : "+option11);
		System.out.println("option12 : "+option12);
		System.out.println("option13 : "+option13);
		System.out.println("option14 : "+option14);
		System.out.println("option15 : "+option15);
		System.out.println("option16 : "+option16);
		System.out.println("option17 : "+option17);
		System.out.println("option18 : "+option18);
		System.out.println("option19 : "+option19);
		System.out.println("option20 : "+option20);
		System.out.println("option21 : "+option21);
		System.out.println("option22 : "+option22);
		System.out.println("option23 : "+option23);
		System.out.println("option24 : "+option24);
		System.out.println("option25 : "+option25);
		System.out.println("option26 : "+option26);
		System.out.println("option27 : "+option27);
		System.out.println("option28 : "+option28);
		System.out.println("option29 : "+option29);
		System.out.println("option30 : "+option30);
		System.out.println("option31 : "+option31);
		
		System.out.println("option04_1: "+option04_1);
		System.out.println("option04_2: "+option04_2);
		System.out.println("option04_3: "+option04_3);
		System.out.println("option15_1: "+option15_1);
		System.out.println("option15_2: "+option15_2);
		System.out.println("option15_3: "+option15_3);
		System.out.println("option16_1: "+option16_1);
		System.out.println("option16_2: "+option16_2);
		System.out.println("option16_3: "+option16_3);
		System.out.println("option17_1: "+option17_1);			
		System.out.println("option17_2: "+option17_2);			
		System.out.println("option17_3: "+option17_3);	
		
		System.out.println("visitDate :	"+visitDate);
		System.out.println("age       : "+age);
		System.out.println("ageRange01:	"+ageRange01);
		System.out.println("ageRange02:	"+ageRange02);
		System.out.println("ageRange03:	"+ageRange03);
		System.out.println("ageRange04:	"+ageRange04);
		System.out.println("ageRange05:	"+ageRange05);
		System.out.println("ageRange06:	"+ageRange06);
		System.out.println("ageRange07:	"+ageRange07);
		System.out.println("ageRange08:	"+ageRange08);
		System.out.println("ageRange09:	"+ageRange09);
		System.out.println("ageRange10:	"+ageRange10);
		System.out.println("ageRange11:	"+ageRange11);
		System.out.println("ageRange12:	"+ageRange12);
		System.out.println("ageRange13:	"+ageRange13);
		System.out.println("ageRange14:	"+ageRange14);
		System.out.println("ageRange15:	"+ageRange15);
		
		//output
		StringHolder answer 		= new StringHolder();
		StringHolder errorMessage 	= new StringHolder();
		StringHolder isComplete 	= new StringHolder();
		BGH_spc_spcProduct_spcRecommendationProxy service = getProductRecService(MessageConstant.END_POINT_PRODUCT_REC);
		System.out.println("start get resultd..");
		
		//manage input
//		service.recommend(q8      , q4Option1 , q23     , ageRange10, q17Option2, q15Option3, age, q31     , q28     , q11     , ageRange6 , ageRange3 , ageRange11, ageRange1 , q7      , height             , diatolic        , q24     , q15Option2, ageRange7 , q3      , ageRange14, weight             , q25     , q22     , q17Option1, q12     , gender             , q4      , q30     , q2      , q18     , ageRange5 , ageRange2 , q29     , q16     , q1      , ageRange8 , q26     , q5      , q19     , q17     , ageRange4 , q4Option3 , q4Option2 , q15Option1, q13     , ageRange13, q15     , pulse             , contactId             , ageRange15, q9      , q27     , q21     , q17Option3, q16Option3, q16Option1, ageRange9 , visitDate, systolic        , q6      , q20     , q16Option2, q14     , q10     , ageRange12, answerId, errorMessage, isComplete);
		service.recommend(option08, option04_1, option23, ageRange10, option17_2, option15_3, age, option31, option28, option11, ageRange06, ageRange03, ageRange11, ageRange01, option07, patient.getHeight(), patient.getDIA(), option24, option15_2, ageRange07, option03, ageRange14, patient.getWeight(), option25, option22, option17_1, option12, patient.getGender(), option04, option30, option02, option18, ageRange05, ageRange02, option29, option16, option01, ageRange08, option26, option05, option19, option17, ageRange04, option04_3, option04_2, option15_1, option13, ageRange13, option15, patient.getHeart(), patient.getContactId(), ageRange15, option09, option27, option21, option17_3, option16_3, option16_1, ageRange09, visitDate, patient.getSYS(), option06, option20, option16_2, option14, option10, ageRange12, answer  , errorMessage, isComplete);
		
		//manage output
		System.out.println("result answerId : "+answer.value);
		patient.setAnswerId(answer.value);
		manageResult(isComplete.value, errorMessage.value);
	
		System.out.println("End recommend...");
	}	
	
	public void updateAnswer(Patient patient, String status) throws CSException, Exception{
		System.out.println("Start updateAnswer...");
		UpdateAnswer_Output result = null;
	
		String contactId 	= patient.getContactId();
		String answerId		= patient.getAnswerId();
		String note			= patient.getNote();
		String price		= ""+patient.getTotalPrice();
		
		BGH_spc_spcUpdate_spcAnswerProxy service = getUpdateAnswerService(MessageConstant.END_POINT_UPDATE_ANSWER);
		System.out.println("start get resultd..");
		
		UpdateAnswer_Input input = new UpdateAnswer_Input();
		input.setContactId(contactId);
		input.setAnswerId(answerId);
		input.setNote(note);
		input.setPrice(price);
		input.setStatus(status);
		System.out.println("input : "+BeanUtils.describe(input));

		//call service
		result = service.updateAnswer(input);
		
		//manage output
		manageResult(result.getIsComplete(), result.getErrorMessage());
			
		System.out.println("End updateAnswer...");
	}	
	
	public void updateProduct(Patient patient, String prodRecId, String buy, String price, String indication, String remark) throws CSException, Exception{
		System.out.println("Start updateProduct...");
		UpdateProduct_Output result = null;
	
		String contactId 	= patient.getContactId();
		String answerId		= patient.getAnswerId();

		BGH_spc_spcUpdate_spcProductProxy service = getUpdateProductService(MessageConstant.END_POINT_UPDATE_ANSWER);
		System.out.println("start get resultd..");
		
		UpdateProduct_Input input = new UpdateProduct_Input();
		input.setContactId(contactId);
		input.setAnswerId(answerId);
		input.setProdRecId(prodRecId);
		input.setBuy(buy);
		input.setPrice(price);
		input.setIndication(indication);
		input.setRemark(remark);
		System.out.println("[CallService.updateProduct] input : "+BeanUtils.describe(input));
		
		//call service
		result = service.updateProduct(input);
		
		//manage output
		manageResult(result.getIsComplete(), result.getErrorMessage());

		System.out.println("End updateProduct...");
	}	
	
	public static void main(String[] args){
		Date date = DateUtils.createDate("07/01/2012", "dd/MM/yyyy");
		System.out.println(date);	
		
		System.out.println(DateUtils.getDateStr(date, "dd/MM/yyyy"));		
	}
}
